"""飞书数据上传脚本"""

import os
import sys
import logging
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent.parent
sys.path.append(str(project_root))

from services.feishu.table_service import FeishuTableService

# 配置日志
logging.basicConfig(
    level=logging.INFO,
    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
    handlers=[
        logging.FileHandler(project_root / 'logs' / 'feishu_upload.log'),
        logging.StreamHandler()
    ]
)

logger = logging.getLogger(__name__)

def main():
    """飞书数据上传主函数"""
    try:
        logger.info("开始飞书数据同步...")
        
        # 创建服务实例
        service = FeishuTableService()
        
        # 处理所有表格
        service.process_all_tables()
        
        logger.info("所有表格处理完成")
        return 0
        
    except Exception as e:
        logger.error(f"飞书数据上传失败: {str(e)}")
        return 1

if __name__ == "__main__":
    sys.exit(main()) 